package com.example.administrator.maizuofilm.moviedetails.moviedetailsadapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.example.administrator.maizuofilm.moviedetails.bean.Details;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hansen on 2016/7/13.
 */
public class MovieDetailsViewPagerAdapter extends PagerAdapter {
    private Context context;
    private List<Details.DataBean.FilmInfosBean> list;
    private List<ImageView> imagelist;
    public MovieDetailsViewPagerAdapter(Context context, List<Details.DataBean.FilmInfosBean> list){
        this.context=context;
        this.list=list;
        imagelist=new ArrayList<>();
        for (int i=0;i<list.size();i++){
            ImageView iv=new ImageView(context);
          //  iv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            iv.setScaleType(ImageView.ScaleType.FIT_XY);
            imagelist.add(iv);
        }
    }

    @Override
    public int getCount() {
        return imagelist.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {


        return view==object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        Glide.with(context).load(list.get(position).getArticlePic()).into(imagelist.get(position));

        container.addView(imagelist.get(position));
        return imagelist.get(position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(imagelist.get(position));
    }
}
